using System;
using System.Configuration;
using UrDnd.IrcBot.ComponentModel.Configuration;
using ConfigurationElement=System.Configuration.ConfigurationElement;
using ConfigurationElementCollection=MedSoft.Library.Configuration.ConfigurationElementCollection;

namespace UrDnd.IrcBot.ComponentModel.Configuration
{
	public class KeyedElementCollection<T> : ConfigurationElementCollection
		where T : ConfigurationElement, IKeyedElement, new()
	{
		///<summary>
		///When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"></see>.
		///</summary>
		///
		///<returns>
		///A new <see cref="T:System.Configuration.ConfigurationElement"></see>.
		///</returns>
		///
		protected override ConfigurationElement CreateNewElement()
		{
			return new T();
		}

		///<summary>
		///Gets the element key for a specified configuration element when overridden in a derived class.
		///</summary>
		///
		///<returns>
		///An <see cref="T:System.Object"></see> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"></see>.
		///</returns>
		///
		///<param name="element">The <see cref="T:System.Configuration.ConfigurationElement"></see> to return the key for. </param>
		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((IKeyedElement) element).Key;
		}

		public new T this[int index]
		{
			get { return (T) base[index]; }
			set { base[index] = value; }
		}

		public new T this[string propertyName]
		{
			get { return (T) base[propertyName]; }
			set { base[propertyName] = value; }
		}

		public new T this[ConfigurationProperty property]
		{
			get { return (T) base[property]; }
			set { base[property] = value; }
		}
	}
}